package com.zkca.xf.presenter;

import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.zkca.xf.base.BasePresenter;
import com.zkca.xf.manager.DataManager;
import com.zkca.xf.model.javabean.DianLiu_Z;
import com.zkca.xf.model.javabean.uploadbean.RequestPage;
import com.zkca.xf.view.DianliuZView;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DefaultObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by li on 2018/9/28.
 */

public class DianliuZPresenter extends BasePresenter {
    private DianliuZView dianliuView;
    private DataManager dataManager;
    public DianliuZPresenter(LifecycleProvider<ActivityEvent> provider,DianliuZView dianliuView) {
        super(provider);
        this.dianliuView=dianliuView;
        dataManager=DataManager.getInstance();
    }
    public void GetDianliuZ(final RequestPage dianliu_requ){
        dianliuView.showProgressDialog();

        dataManager.getDianliuZ(dianliu_requ)
                .subscribeOn(Schedulers.io())// 在子线程中进行Http访问
                .observeOn(AndroidSchedulers.mainThread())// UI线程处理返回接口
                .compose(getProvider().<DianLiu_Z>bindUntilEvent(ActivityEvent.DESTROY))//
                .subscribe(new DefaultObserver<DianLiu_Z>() {
                    @Override
                    public void onNext(DianLiu_Z dianliu) {
                        dianliuView.getDianliuZ(dianliu);
                    }

                    @Override
                    public void onError(Throwable e) {
                        dianliuView.hideProgressDialog();
                        dianliuView.showError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        dianliuView.hideProgressDialog();
                    }
                });
    }

}
